import serial
import time

# 配置串口通信参数
serial_port = 'COM6'
baudrate = 9600

# 创建串口连接
ser = serial.Serial(
    port=serial_port,
    baudrate=baudrate
)

# 检查串口是否已打开
if ser.is_open:

    try:

        hex_data = bytes.fromhex('01 10 00 10 00 01 02 00 00 A4 C0')
        ser.write(hex_data)

        time.sleep(1)

    except KeyboardInterrupt:

        pass

    # 关闭串口连接
    ser.close()
else:
    print(f'Failed to open serial port {serial_port}.')
